import { defineStore } from "pinia";
import { useRouter } from "vue-router";

export const useTabsMeun = defineStore('tabsMeun', {
    state() {
        return {
            tabsMeun: [{
                path: "/index",
                name: "Index",
                title: "数据分析",
                active: true,//是否激活
                closeAble: false//是否可以关闭
            }]
        }
    },
    getters: {
        topTabsMeun(state) {
            return state.tabsMeun
        }
    },
    actions: {
        changeTabs(val: any) {
            let index = this.tabsMeun.findIndex(item => item.name == val.name)
            this.tabsMeun.forEach((item) => {
                item.active = false
            })
            if (index == -1) {
                this.tabsMeun.push({
                    path: val.path,
                    name: val.name,
                    title: val.title,
                    closeAble: true,
                    active: true
                })
            }
            else {
                this.tabsMeun[index].active = true
            }
        },
        deleteTabs(val: any[]) {
            this.tabsMeun = this.tabsMeun.filter((item) => {
                return val.every((child) => {
                    return child.name !== item.name
                })
            })
        }
    }
});